﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace LightSwitchApplication.UserCode
{
    public class TraingroupService
    {
        private ApplicationData ApplicationData;

        public TraingroupService(ApplicationData appData)
        {
            this.ApplicationData = appData;
        }

        /* NOW IMPLEMETED IN CustomDataService
        public string getStakeholderPropertyStringConcat(tlTraingroup traingroup, int propertyId)
        {
            using (SqlConnection connection = new SqlConnection())
            {
                // Todo: Find a way to get the connectionStingName - not just guessing it right.
                string connectionStringName = "_IntrinsicData"; //Maybe this won't work in deployed app
                connection.ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;

                string procedure = "dbo.spGetStakeholderPropertiesForTraingroup";

                string concatString = "";
                using (SqlCommand command = new SqlCommand(procedure, connection))  // Fire StoredProcedure
                {
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.Add(new SqlParameter("@TraingroupId", traingroup.Id));
                    command.Parameters.Add(new SqlParameter("@StaticCustomPropertyId", propertyId));

                    SqlDataAdapter dataAdapter = new SqlDataAdapter(command);

                    DataSet dataSet = new DataSet();
                    dataAdapter.Fill(dataSet, "result");

                    DataTable dataTable = dataSet.Tables["result"];

                    foreach (DataRow row in dataTable.Rows)
                    {
                        concatString += row["CustomPropertyValue"];
                        if (row != dataTable.Rows[dataTable.Rows.Count - 1])
                            concatString += "; ";
                    }
                }
                return concatString;
            }
        }
         * */

    }
}